package com.marakana.yamba4;

import com.chris.weibo.R;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class TimeLineActivity3 extends Activity {

	DbHelper dbHelper;
	SQLiteDatabase db;
	Cursor cursor;
	ListView listTimeLine;
	TimeLineAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_timeline);

		listTimeLine = (ListView) findViewById(R.id.listTimeLine);
		dbHelper = new DbHelper(this);
		db = dbHelper.getReadableDatabase();
	}

	@Override
	protected void onResume() {
		super.onResume();

		// 从数据库中读取数据
		cursor = db.query(DbHelper.TABLE, null, null, null, null, null,
				DbHelper.C_CREATED_AT + " DESC");
		startManagingCursor(cursor);

		// 设置Adapter
		adapter = new TimeLineAdapter(this, cursor);
		listTimeLine.setAdapter(adapter);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		db.close();
	}

}
